/*
 * Copyright (c) 2019 DawnFramework. All Rights Reserved.
 * Licensed under the MIT (LICENSE) license.
 */

package org.dawn.common.service.service;

import java.util.Collection;
import java.util.function.Consumer;
import java.util.function.Supplier;

/**
 * @author Willard Hu on 2017/4/25.
 */
public class ServiceTPageResponse<T> extends ServicePageResponse {
    private static final long serialVersionUID = -7485341684601771427L;

    private Collection<T> values;

    public ServiceTPageResponse<T> setValues(Collection<T> values) {
        this.values = values;
        return this;
    }

    public Collection<T> getValues() {
        return values;
    }

    public boolean ifPresent() {
        return values != null && !values.isEmpty();
    }

    public void ifPresent(Consumer<Collection<? super T>> consumer) {
        if (ifPresent()) {
            consumer.accept(values);
        }
    }

    public Collection<T> orElse(Collection<T> other) {
        return ifPresent() ? values : other;
    }

    public Collection<T> orElseGet(Supplier<Collection<T>> other) {
        return ifPresent() ? values : other.get();
    }
}
